/**
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

% Panda::instructions.select{|b| b.namespace == "ecmascript"}.each do |inst|
    case RuntimeInterface::IntrinsicId::DYN_<%= inst.opcode.upcase %>:
    {
        constexpr auto CLEAR_FLAGS = ark::compiler::inst_flags::BARRIER|ark::compiler::inst_flags::REQUIRE_STATE|ark::compiler::inst_flags::CALL|ark::compiler::inst_flags::HEAP_INV|ark::compiler::inst_flags::CAN_THROW|ark::compiler::inst_flags::ACC_READ|ark::compiler::inst_flags::ACC_WRITE;
        constexpr auto SET_FLAGS = 0U;
        static_assert((SET_FLAGS & CLEAR_FLAGS) == 0, "DYN_<%= inst.opcode.upcase %> CLEAR_FLAGS cannot intersect SET_FLAGS");
        inst->ClearFlag(static_cast<inst_flags::Flags>(CLEAR_FLAGS));
%   if inst.throwing?
        inst->SetFlag(ark::compiler::inst_flags::CAN_THROW);
%   end
%   if inst.exceptions.include?('x_throw') || inst.properties.include?('return')
        inst->SetFlag(ark::compiler::inst_flags::CF);
        inst->SetFlag(ark::compiler::inst_flags::TERMINATOR);
%   end
%   if inst.acc.include?("in")
        inst->SetFlag(ark::compiler::inst_flags::ACC_READ);
%   end
%   addition_acc_write_opcodes = ["DEFINEPROPERTYBYNAME_IMM8_ID16_V8",
%                                 "CALLRUNTIME_DEFINEFIELDBYVALUE_PREF_IMM8_V8_V8",
%                                 "CALLRUNTIME_DEFINEPRIVATEPROPERTY_PREF_IMM8_IMM16_IMM16_V8",
%                                 "STPRIVATEPROPERTY_IMM8_IMM16_IMM16_V8",
%                                 "THROW_UNDEFINEDIFHOLEWITHNAME_PREF_ID16"]
%   if inst.acc.include?("out") || (addition_acc_write_opcodes.include? inst.opcode.upcase)
        inst->SetFlag(ark::compiler::inst_flags::ACC_WRITE);
%   end
        break;
    }
% end
